﻿#include "saleswoman.h"

#include "../../Include/iframework.h"
#include "../../Include/icommon.h"
#include "../../Include/ilogger.h"
#include "../../Include/inetcomm.h"
#include "../../Include/iconfig.h"

CSaleswoman::CSaleswoman()
{

}

CSaleswoman::~CSaleswoman()
{

}

int CSaleswoman::Init()
{
    m_pLogger->WriteLog("CSalewoman::Init()");
    m_pFramework->GetConfig(&m_pConfig);
    m_pFramework->GetNetComm(&m_pNetComm);
    m_pFramework->GetCommon(&m_pCommon);
    connect(this,&CSaleswoman::sigPostTrdMsg,this,&CSaleswoman::slotGetTrdMsg);
    this->moveToThread(&m_thread);
    m_thread.start();
    return 1;
}

int CSaleswoman::UnInit()
{
    m_pLogger->WriteLog("CSaleswoman::UnInit()");
    m_thread.quit();
    if(m_thread.wait())
    {
        m_thread.terminate();
        m_thread.wait(3000);
    }
    return 1;
}

int CSaleswoman::SetFramework(IFramework *pFrm)
{
    m_pFramework = pFrm;
    m_pFramework->GetLogger(&m_pLogger);
    return 1;
}

int CSaleswoman::PostThreadMsg(int nType, QString data)
{
    emit sigPostTrdMsg(nType, data);
    return 1;
}

void CSaleswoman::slotGetTrdMsg(int nType, QString msg)
{
    qDebug() << "CSaleswoman::slotGetTrdMsg thread id=" << QThread::currentThreadId();
    switch(nType)
    {
    case trd_saleswoman_test:
    {
        static int testCount = 0;
        testCount++;
        QString szLog = QString("---------saleswoman test msg timer count=%1").arg(testCount);
        m_pLogger->WriteLog(szLog);
    }
        break;
    case message_cbuitest_saleswoman:{
        qDebug() << u8"woman线程收到消息, woman线程ID=" << QThread::currentThreadId();
        pfnUICommBridge pfn = NULL; void *userdata = NULL;
        m_pFramework->GetCBUICommBridge(&pfn, (void**)&userdata);
        UI_Comm_Bridge rst;
        rst.msgtype = cb_ui_type_womantest;
        pfn(&rst, userdata);
    } break;
    default:break;
    }
}
